package com.haixiaoke.flat.workOrder.controller;

import com.haixiaoke.auth.AuthCheck;
import com.haixiaoke.saas.common.core.domain.AjaxResult;
import com.haixiaoke.saas.common.core.page.TableDataInfo;
import com.haixiaoke.saas.system.BaseController;
import com.haixiaoke.saas.workOrder.domain.WorkOrderEvaluate;
import com.haixiaoke.saas.workOrder.service.IWorkOrderEvaluateService;
import com.haixiaoke.token.FrontTokenComponent;
import com.haixiaoke.token.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;


/**
 * 工单评价Controller
 *
 * @author qixi
 * @date 2024-09-04
 */
@RestController
@RequestMapping("/front/flat/workOrder/evaluate")
public class FlatWorkOrderEvaluateController extends BaseController {

    @Autowired
    private IWorkOrderEvaluateService workOrderEvaluateService;
    @Autowired
    private FrontTokenComponent frontTokenComponent;

    /**
     * 查询工单评价列表
     */
    @PreAuthorize("@ss.hasPermi('evaluate:evaluate:list')")
    @GetMapping("/list")
    public TableDataInfo list(WorkOrderEvaluate workOrderEvaluate) {
        startPage();
        List<WorkOrderEvaluate> list = workOrderEvaluateService.selectWorkOrderEvaluateList(workOrderEvaluate);
        return getDataTable(list);
    }

    /**
     * 新增工单评价
     */
    @AuthCheck
    @PostMapping
    public AjaxResult add(@RequestBody @Valid WorkOrderEvaluate workOrderEvaluate) {
        LoginUser loginUser = frontTokenComponent.getLoginUser();
        workOrderEvaluate.setCreateBy(loginUser.getUser().getUserName());
        return toAjax(workOrderEvaluateService.evaluateWorkOrder(workOrderEvaluate));
    }


}
